package GUILayer;

import java.awt.EventQueue;

import ControlLayer.Ctr;
import GUILayer.ProductTable;

import javax.swing.JFrame;
import javax.swing.JTabbedPane;

import java.awt.BorderLayout;

import javax.swing.JPanel;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JList;
import javax.swing.AbstractListModel;
import javax.swing.ListSelectionModel;
import javax.swing.JScrollBar;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JButton;

import java.awt.Font;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

import ModelLayer.*;

import javax.swing.JTable;
import javax.swing.table.TableModel;
public class Administration {
	private Product product;
	private Ctr ctr;
	private JFrame frame;
	private JTextField txtInsertItemName;
	private JTextField txtInsertItmeId;
	private JTextField txtInputSupplierName;
	private JTextField txtInputSupplierId;
	private JTextField textField_1;
	private JTable table;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					Administration window = new Administration();
					window.frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the application.
	 */
	public Administration() {
		initialize();
	}

	/**
	 * Initialize the contents of the frame.
	 */
	private void initialize() {
		frame = new JFrame();
		frame.setBounds(100, 100, 650, 520);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.getContentPane().setLayout(null);
		
		JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP);
		tabbedPane.setBounds(0, 0, 634, 482);
		frame.getContentPane().add(tabbedPane);
		
		JPanel ItemTab = new JPanel();
		tabbedPane.addTab("Item", null, ItemTab, null);
		ItemTab.setLayout(null);
		
		JLabel lblNewLabel = new JLabel("Item Type");
		lblNewLabel.setBounds(10, 25, 68, 21);
		ItemTab.add(lblNewLabel);
		
		JScrollPane scrollPane = new JScrollPane();
		scrollPane.setBounds(121, 11, 121, 59);
		ItemTab.add(scrollPane);
		
		JList list = new JList();
		scrollPane.setViewportView(list);
		list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
		list.setVisibleRowCount(1);
		list.setModel(new AbstractListModel() {
			String[] values = new String[] {"Clothing", "Equipment", "Gun"};
			public int getSize() {
				return values.length;
			}
			public Object getElementAt(int index) {
				return values[index];
			}
		});
		
		JLabel lblItemName = new JLabel("Item Name");
		lblItemName.setBounds(10, 93, 72, 21);
		ItemTab.add(lblItemName);
		
		JTextArea textArea = new JTextArea();
		textArea.setBounds(121, 91, 121, 22);
		ItemTab.add(textArea);
		
		JLabel lblItemPrice = new JLabel("Sale Price");
		lblItemPrice.setBounds(274, 61, 72, 14);
		ItemTab.add(lblItemPrice);
		
		JTextArea textArea_1 = new JTextArea();
		textArea_1.setBounds(379, 23, 121, 22);
		ItemTab.add(textArea_1);
		
		JLabel lblPurchasePrice = new JLabel("Purchase Price");
		lblPurchasePrice.setBounds(274, 28, 95, 14);
		ItemTab.add(lblPurchasePrice);
		
		JTextArea textArea_2 = new JTextArea();
		textArea_2.setBounds(379, 56, 121, 22);
		ItemTab.add(textArea_2);
		
		JLabel lblRentPrice = new JLabel("Rent Price");
		lblRentPrice.setBounds(270, 96, 76, 14);
		ItemTab.add(lblRentPrice);
		
		JTextArea textArea_3 = new JTextArea();
		textArea_3.setBounds(379, 91, 121, 22);
		ItemTab.add(textArea_3);
		
		JLabel lblCountryOfOrigin = new JLabel("Country of origin");
		lblCountryOfOrigin.setBounds(10, 138, 98, 14);
		ItemTab.add(lblCountryOfOrigin);
		
		JTextArea textArea_4 = new JTextArea();
		textArea_4.setBounds(121, 138, 121, 22);
		ItemTab.add(textArea_4);
		
		JLabel lblQuantitiy = new JLabel("Quantitiy");
		lblQuantitiy.setBounds(263, 138, 59, 14);
		ItemTab.add(lblQuantitiy);
		
		JTextArea textArea_5 = new JTextArea();
		textArea_5.setBounds(315, 133, 39, 22);
		ItemTab.add(textArea_5);
		
		JLabel lblItemId = new JLabel("Item ID");
		lblItemId.setBounds(379, 138, 54, 14);
		ItemTab.add(lblItemId);
		
		JTextArea textArea_6 = new JTextArea();
		textArea_6.setBounds(430, 133, 39, 22);
		ItemTab.add(textArea_6);
		
		JButton btnAddItem = new JButton("Add\r\n Item");
		btnAddItem.setBounds(525, 11, 94, 109);
		ItemTab.add(btnAddItem);
		
		JLabel lblSupl = new JLabel("Supplier ID");
		lblSupl.setBounds(492, 138, 68, 14);
		ItemTab.add(lblSupl);
		
		JTextArea textArea_7 = new JTextArea();
		textArea_7.setBounds(556, 133, 39, 22);
		ItemTab.add(textArea_7);
		
		txtInsertItemName = new JTextField();
		txtInsertItemName.setText("Insert Item Name");
		txtInsertItemName.setBounds(21, 227, 143, 20);
		ItemTab.add(txtInsertItemName);
		txtInsertItemName.setColumns(10);
		
		txtInsertItmeId = new JTextField();
		txtInsertItmeId.setText("Insert Item ID");
		txtInsertItmeId.setBounds(197, 227, 107, 20);
		ItemTab.add(txtInsertItmeId);
		txtInsertItmeId.setColumns(10);
		
		JButton btnFindItem = new JButton("Find Product");
		btnFindItem.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				
				product =ctr.findBypID(Integer.parseInt(txtInsertItmeId.getText()));
				
			}
		});
		btnFindItem.setBounds(315, 226, 108, 23);
		ItemTab.add(btnFindItem);
		
		JButton btnDeleteSelected = new JButton("Delete Selected");
		btnDeleteSelected.setFont(new Font("Tahoma", Font.PLAIN, 10));
		btnDeleteSelected.setBounds(512, 273, 107, 36);
		ItemTab.add(btnDeleteSelected);
		
		JButton btnUpdateSelected = new JButton("Update Selected");
		btnUpdateSelected.setFont(new Font("Tahoma", Font.PLAIN, 10));
		btnUpdateSelected.setBounds(512, 327, 107, 36);
		ItemTab.add(btnUpdateSelected);
		
		JButton btnNewButton = new JButton("Back");
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				frame.dispose();
			}
		});
		btnNewButton.setBounds(512, 384, 107, 34);
		ItemTab.add(btnNewButton);
		
		table = new JTable();
		table.setBounds(22, 283, 447, 163);
		ItemTab.add(table);
		
		JButton btnFindAllProducts = new JButton("Find All Products");
		btnFindAllProducts.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				TableModel model = new ProductTable();
				table.setModel(model);
			}
		});
		btnFindAllProducts.setBounds(442, 226, 118, 23);
		ItemTab.add(btnFindAllProducts);
		
		JPanel panel = new JPanel();
		tabbedPane.addTab("Supplier\r\n", null, panel, null);
		panel.setLayout(null);
		
		JLabel lblSupplierName = new JLabel("Supplier Name");
		lblSupplierName.setBounds(20, 36, 85, 14);
		panel.add(lblSupplierName);
		
		JLabel lblNewLabel_1 = new JLabel("Address");
		lblNewLabel_1.setBounds(20, 73, 70, 14);
		panel.add(lblNewLabel_1);
		
		JLabel lblCountry = new JLabel("Country");
		lblCountry.setBounds(284, 36, 57, 14);
		panel.add(lblCountry);
		
		JLabel lblEmail = new JLabel("E-mail");
		lblEmail.setBounds(284, 73, 57, 14);
		panel.add(lblEmail);
		
		JLabel lblPhoneNo = new JLabel("Phone No");
		lblPhoneNo.setBounds(20, 111, 70, 14);
		panel.add(lblPhoneNo);
		
		JTextArea textArea_8 = new JTextArea();
		textArea_8.setBounds(115, 31, 137, 22);
		panel.add(textArea_8);
		
		JTextArea textArea_9 = new JTextArea();
		textArea_9.setBounds(115, 68, 137, 22);
		panel.add(textArea_9);
		
		JTextArea textArea_10 = new JTextArea();
		textArea_10.setBounds(115, 106, 137, 22);
		panel.add(textArea_10);
		
		JTextArea textArea_11 = new JTextArea();
		textArea_11.setBounds(340, 31, 137, 22);
		panel.add(textArea_11);
		
		JTextArea textArea_12 = new JTextArea();
		textArea_12.setBounds(340, 68, 137, 22);
		panel.add(textArea_12);
		
		JLabel lblId = new JLabel("ID");
		lblId.setBounds(284, 111, 46, 14);
		panel.add(lblId);
		
		JTextArea textArea_13 = new JTextArea();
		textArea_13.setBounds(340, 106, 46, 22);
		panel.add(textArea_13);
		
		JButton btnAddSupplier = new JButton("Add Supplier");
		btnAddSupplier.setBounds(508, 32, 111, 93);
		panel.add(btnAddSupplier);
		
		txtInputSupplierName = new JTextField();
		txtInputSupplierName.setText("Input Supplier Name");
		txtInputSupplierName.setBounds(20, 202, 128, 20);
		panel.add(txtInputSupplierName);
		txtInputSupplierName.setColumns(10);
		
		txtInputSupplierId = new JTextField();
		txtInputSupplierId.setText("Input Supplier ID");
		txtInputSupplierId.setBounds(183, 202, 111, 20);
		panel.add(txtInputSupplierId);
		txtInputSupplierId.setColumns(10);
		
		JButton btnFindSupplier = new JButton("Find Supplier");
		btnFindSupplier.setBounds(340, 201, 111, 23);
		panel.add(btnFindSupplier);
		
		textField_1 = new JTextField();
		textField_1.setBounds(19, 243, 458, 137);
		panel.add(textField_1);
		textField_1.setColumns(10);
		
		JButton btnDeletSelected = new JButton("Delete Selected");
		btnDeletSelected.setFont(new Font("Tahoma", Font.PLAIN, 10));
		btnDeletSelected.setBounds(498, 259, 111, 38);
		panel.add(btnDeletSelected);
		
		JButton btnUpdateSelected_1 = new JButton("Update Selected");
		btnUpdateSelected_1.setFont(new Font("Tahoma", Font.PLAIN, 10));
		btnUpdateSelected_1.setBounds(498, 308, 111, 38);
		panel.add(btnUpdateSelected_1);
		
		JButton btnNewButton_1 = new JButton("Back");
		btnNewButton_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				frame.dispose();
			}
		});
		btnNewButton_1.setBounds(498, 393, 111, 38);
		panel.add(btnNewButton_1);
	}
}
